<?php
function dobook($bid,$cid){
		$xxxml			=	ROOT_PATH."/xml.xml";
		$bbid	=	floor($bid/1000);
		$cachexmlname	=	ROOT_PATH."/cached/c/xml/".$bbid."/".$bid."/".$cid.".xml";
		$openurl	=	"http://www.3zcn.com/3z".$bid."-".$cid.".html";
		$file	=	curl($openurl);
		$file 	=	iconv("GBK", "UTF-8//IGNORE", $file);
		$title	=	cut($file,"<h1>","</h1>");
		$preview_page	=	cut($file,"preview_page = \"/3z".$bid."-",".html");
		$nextpage	=	cut($file,"next_page = \"/3z".$bid."-",".html");
		$content	=	cut($file,"script>&nbsp;&nbsp;&nbsp;&nbsp;","<font class=\"tips\">");
		$content	=	str_replace("</div>","",$content);
		$content	=	str_replace("<br /><br />","<br />",$content);
		//$content	=	str_replace("&nbsp;","",$content);
		//echo $title."<br /> \n";
		//var preview_page = "/3z62542-3446253.html";
//var next_page = "/3z62542-3446255.html";
//var index_page = "/3z62542.html";

			if($preview_page == "index"){
				$preview_page_c		=	"book.php?bid=".$bid;
				$pcid				=	"";
			}
			else{
				$preview_page_c	=	"reader.php?bid=".$bid."&cid=".$preview_page;
				$pcid			=	$preview_page;
			}
			if($nextpage == "index"){
				$nextpage_c		=	"book.php?bid=".$bid;
				$ncid				=	"";
			}
			else{
				$nextpage_c		=	"reader.php?bid=".$bid."&cid=".$nextpage;
				$ncid				=	$nextpage;
			}
//缓存不存在，远程采集子程序结束
//XML处理程序开始
		$xml = new SimplexmlElement($xxxml,NULL,TRUE);
		$books	=	$xml->addChild('books');
		$books->addChild('title',xmlencode($title));
		$books->addChild('bid',xmlencode($bid));
		$books->addChild('pcid',xmlencode($pcid));
		$books->addChild('ncid',xmlencode($ncid));
		$books->addChild('content',xmlencode($content));
		$xml->asXML($cachexmlname);
}
function xmlencode($tag)
{
$tag = str_replace("&", "&amp;", $tag);
$tag = str_replace("<", "&lt;", $tag);
$tag = str_replace(">", "&gt;", $tag);
$tag = str_replace("'", "&apos;", $tag);
$tag = str_replace("\"", '&quot;', $tag);
return $tag;
}
?>